package level4.engines.components
{
	import level4.interfaces.IGameComponent;
	import level4.interfaces.dispose.IDisposable;
	import level4.engines.GameEngine;

	/**
	 * 可让GameEngine管理的组件.
	 * */
	public class GameComponent implements IGameComponent,IDisposable
	{
		//update
		private var callback:Function;
		
		public function GameComponent(callback:Function)
		{
			this.callback = callback;
			GameEngine.addComponent(this);
		}
		/**
		 * 更新,每帧
		 * */
		public function update(timeDiff:Number):void{
			if(callback != null){
				callback(timeDiff);
			}else{
				throw("GameEngineComponent need callback!");
			}
		}
		/**
		 * 卸载
		 * */
		public function dispose():void{
			GameEngine.removeComponent(this);
			callback = null;
		}
	}
}